package net.tngou.iask.service;

import java.util.List;
import java.util.Map;

import net.tngou.iask.dao.MsgsDao;
import net.tngou.iask.jdbc.PageUtil;
import net.tngou.iask.pojo.At;
import net.tngou.iask.pojo.Msgs;

/**
 * 私信、消息
 * @author tngou@tngou.net
 *
 */
public class MsgsService extends BaseService {
	/**
	 * 取得私信
	 * @param user
	 * @param friend
	 * @param page
	 * @param size
	 * @return
	 */
	public PageUtil getPage(long user,long friend,int page,int size) {
		MsgsDao dao = new MsgsDao();
		return dao.getPage(user, friend, page, size);
	}
	/**
	 * 取得用户未读消息
	 * @param user
	 * @return
	 */
	public List<Map<String, Object>> getList(long user) {
		MsgsDao dao = new MsgsDao();
		return dao.getList(user);
	}
	
	
	/**
	 * 发送At功能
	 */
	public void sendAt(String title,String url,long ...users) {
		for (int i = 0; i < users.length; i++) {
			At at= new At();
			at.setTitle(title);
			at.setUrl(url);
			at.setUser(users[i]);
			at.setIsread(0);
			at.save();
		}
	}
	
	/**
	 * 发送系统消息
	 * @param msg
	 * @param users
	 */
	public void sendSys(String msg,long ...users) {
		for (int i = 0; i < users.length; i++) {
			Msgs msgs = new Msgs();
			msgs.setType(1);
			msgs.setUser(users[i]);
			msgs.setIsread(0);
			msgs.save();
		}
		
	}
	
	
	/**
	 * 设置已读
	 * @param user
	 * @param friend
	 */
	public void setRead(long user,long friend) {
		MsgsDao dao = new MsgsDao();
		dao.setRead(user, friend);
	}
}
